import Vue from 'vue'
import App from './App.vue'
import router from './router'
import Login from './Login'
import axios from 'axios'
import bus from './bus/Bus'
import store from './store'
import "@/filters"
import "@/components"




import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);
Vue.prototype.$http=axios
Vue.prototype.$bus=bus
Vue.config.productionTip = false
//请求拦截
axios.interceptors.request.use(config=>{
  store.commit('CHANGE_TRUE',true)
  config.url='/api'+config.url+(config.url.includes("?")?"&":"?")+"t="+Date.now();
  config.headers={
    authorization:store.state.admin.token
  }
  return config
})
//响应拦截
axios.interceptors.response.use(({data})=>{
  store.commit('CHANGE_TRUE',false)
  if(data.ok===-2){
    store.commit("CHANGE_FALSE")
  }else{
    if(data.pageSum){
      store.commit("CHANGE_PAGE_SUM",data.pageSum)
    }
  }
  return data
})

new Vue({
  store,
  router,
  render: function (h) { return h(store.state.admin.adminName?App:Login) }
}).$mount('#app')
